﻿// Write a program that enters the coefficients a, b and c of a quadratic equation
//		a*x2 + b*x + c = 0
// and calculates and prints its real roots. Note that quadratic equations may have 0, 1 or 2 real roots.


using System;

class SolveQuadraticEquation
{
    static void Main()
    {
        Console.Write("Enter fisrt coefficient : ");
        string aStr = Console.ReadLine();
        double a;
        while (!double.TryParse(aStr, out a))
        {
            Console.Write("Invalid input! Please, entere coefficient a again : ");
            aStr = Console.ReadLine();
        }

        Console.Write("Enter second coefficient : ");
        string bStr = Console.ReadLine();
        double b;
        while (!double.TryParse(bStr, out b))
        {
            Console.Write("Invalid input! Please, entere coefficient b again : ");
            bStr = Console.ReadLine();
        }

        Console.Write("Enter third coefficient : ");
        string cStr = Console.ReadLine();
        double c;
        while (!double.TryParse(cStr, out c))
        {
            Console.Write("Invalid input! Please, entere coefficient c again : ");
            cStr = Console.ReadLine();
        }

        double discriminant = b * b - 4 * a * c;

        if (a == 0 && b == 0 & c == 0)
        {
            Console.WriteLine("This is not an equation.");
        }
        else if (a == 0 && b == 0)
        {
            Console.WriteLine("This is not an equation.");
        }
        else if (a == 0 && b != 0)
        {
            Console.WriteLine("The equation is not quadratic.");
            double result = -c / b;
            Console.WriteLine("The root of the equation is {0}", result);
            Console.WriteLine();
        }
        else if (discriminant < 0)
        {
            Console.WriteLine("The quadratic equation doesn't have real roots.");
            Console.WriteLine("");
        }
        else
        {
            double root1 = (-b + Math.Sqrt(discriminant)) / (2 * a);
            double root2 = (-b - Math.Sqrt(discriminant)) / (2 * a);
            Console.WriteLine("The first root of the quadratic equation is {0:F3} and the second root is {1:F3}", root1, root2);
        }
    }
}
